clc
clear
close all
designs = {'Data\design','Data\design2'};

ec_index_2_5 = [7,8];
ec_index_5 = [1,2,9,10];
ec_index_10 = [3,4];

em_index_2_5 = [9,10];
em_index_5 = [7,8,15,16];
em_index_10 = [13,14];


et_index_1_5_changed = [7,8];
et_index_3_changed = [9,10,13,14];
et_index_6_changed = [15,16];
et_index_3_confirmed = [3,4];
et_index_6_confirmed = [1,2];

for i = 1:2
    design_folder = designs{i};
    subject_types = dir(design_folder);
    num_types = length(subject_types);
    for j = 3:num_types
        type_folder = subject_types(j).name;
        types_data = dir(strcat(design_folder,'\',type_folder));
        num_data = length(types_data);
        Epistemic_Credulity_array = zeros(num_data-2,1);
        Epistemic_Mistrust_array = zeros(num_data-2,1);
        Epistemic_Trust_array = zeros(num_data-2,1);
        data_name = cell(num_data-2,1);
        for k = 3:num_data
            data_folder = types_data(k).name;
            data_address =  dir(strcat(types_data(k).folder,'\',data_folder,'\*.mat'));
            if ~isempty(data_address)
                data_name{k-2} =  data_address.name(1:end-4);
                load(strcat(data_address.folder,'\',data_address.name))
                
                Epistemic_Credulity_array(k-2) = 2.5*sum(changed(ec_index_2_5)) + 5*sum(changed(ec_index_5)) + ...
                    10*sum(changed(ec_index_10));

                Epistemic_Mistrust_array(k-2) = 2.5*sum(confirmed(em_index_2_5)) + 5*sum(confirmed(em_index_5)) +...
                   10*sum(confirmed(em_index_10));

                Epistemic_Trust_array(k-2) = 1.5*sum(changed(et_index_1_5_changed)) + 3*sum(changed(et_index_3_changed)) + ...
                    6*sum(changed(et_index_6_changed)) + 3*sum(confirmed(et_index_3_confirmed)) +...
                    6*sum(confirmed(et_index_6_confirmed));
                
            else
                data_name{k-2} = 'no data';
                Epistemic_Credulity_array(k-2) = nan;
                Epistemic_Mistrust_array(k-2) = nan;
                Epistemic_Trust_array(k-2) = nan;
            end
        end
        Data = data_name;
        Epistemic_Credulity = Epistemic_Credulity_array;
        Epistemic_Mistrust = Epistemic_Mistrust_array;
        Epistemic_Trust = Epistemic_Trust_array;
        t = table(Data,Epistemic_Credulity,Epistemic_Mistrust,Epistemic_Trust);
        writetable(t,strcat(design_folder(6:end),'-',type_folder,'.xls'));
    end  
end
fprintf('Finished !!! \n')
